package xiaohao.order.manager.impl;

import java.util.List;

import xiaohao.order.dao.RateDao;
import xiaohao.order.domain.RateDO;
import xiaohao.order.exception.RateException;
import xiaohao.order.manager.RateManager;

import com.taobao.api.domain.Order;
import com.taobao.api.domain.Trade;
import com.taobao.api.domain.TradeRate;

public class DefaultRateManager implements RateManager {

	@Override
	public TradeRate buyerRate(Trade trade, RateDO rateDO, String sessionKey) throws RateException {
		List<Order> orders = trade.getOrders();
		if (orders.size() == 1 && orders.get(0).getOid() == trade.getTid()) {
			return rateDao.buyerRateSingle(trade.getTid(), orders.get(0).getOid(), rateDO, sessionKey);
		} else {
			return rateDao.buyerRateBatch(trade.getTid(), rateDO, sessionKey);
		}
	}
	
	private RateDao rateDao;

	public void setRateDao(RateDao rateDao) {
		this.rateDao = rateDao;
	}
	
}
